package PhienBanIO;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.text.SimpleDateFormat;

public class DuyetCacFile {
public	static void main (String [] args){
		
		File f= new File("D:\\"); //Duong dan den thu muc
		String [] a = f.list(); // lay ten file
		int soFile = a.length; // lay so luong file trong thu muc
		double[]	bytes = new double [soFile]; 
		File [] files= f.listFiles(); // lay duong dan day du den file
		int [] kt = new int [soFile]; // lay phan mo rong
		SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm"); // dinh dan hien thi thoi gian thay doi file
		String extension = ""; // phan mo rong cua file
		System.out.println("|-----------------------------------------------------------------------|");
		System.out.println("|----------------------------Danh sach file ----------------------------|");
		System.out.println("|-----------------------------------------------------------------------|");
		System.out.println("|   TenFile                  |   last modified   |   Type   |    Size   |");
		System.out.println("|-----------------------------------------------------------------------|");
		//thuc hien hien thi ten va thong tin cua cac file
		for(int i=0;i<soFile;i++){
			if (files[i].isDirectory()==true)
				continue;
			bytes[i]=files[i].length(); // size of file
			double mb =bytes[i]/1024;	// chuyen sang KB
			if(mb<1.0)
				mb=1;			// lam tron size
			//tim kiem phan mo rong
			kt[i] = a[i].lastIndexOf(".");
			if(kt[i]>0){
				extension = a[i].substring(kt[i]+1);
				
			}
			System.out.printf("|%-27s | %s  | %-8s | %5.0f KB  | \n",a[i],sdf.format(files[i].lastModified()),extension,mb);
			System.out.println("|-----------------------------------------------------------------------|");	
		}
		
	}
}

